<template>
    <div>
        <i-table  border :columns="columnsTable" :data="dataList">
            <template slot-scope="{ row }" slot="action">
                <div class="action-button">
                    <Button v-if="row.dept_audit_status==='draft'" type="primary" size="small" style="margin-right: 5px" @click="toEdit(row.imp_date)">编辑</Button>
                    <Button v-if="row.dept_audit_status==='draft'" type="error" size="small" style="margin-right: 5px" @click="deleteDataModal(row.id)">删除</Button>
                    <Button type="success" size="small" @click="toDetail(row.imp_date)">详情</Button>
                </div>
            </template>
        </i-table>
        <Page :total="pageInfo.total" :current="pageInfo.pageNo" @on-change="changePage" />
        <Modal
                v-model="modal"
                title="确认操作"
                width="20"
                @on-ok="deleteData">
            <div style="text-align:center">
                <p>是否确认删除!</p>
            </div>
        </Modal>
    </div>
</template>

<script>
import { findPageList, deletes } from '@/api/outbreak-management/city-operation/public-places/public-place'
// 公共场所--场所信息
export default {
  name: 'publicPlaces',
  data () {
    return {
      // 弹出窗控制
      modal: false,
      // 删除 id
      currentDelId: '',
      columnsTable: [
        {
          title: '上报日期',
          minWidth: 120,
          key: 'date',
          render: (h, params) => {
            let date = this.$common.moment(params.row.imp_date).format('YYYY-MM-DD')
            return h('div', date)
          }
        },
        {
          title: '场所名称',
          minWidth: 120,
          key: 'sence_name'
        },
        {
          title: '人流量',
          minWidth: 120,
          key: 'flow'
        },
        {
          title: '是否营业',
          minWidth: 120,
          key: 'status',
          render: (h, params) => {
            let date = ''
            switch (params.row.status) {
              case '0': date = '营业'
                break
              case '1': date = '停业'
                break
            }
            return h('div', date)
          }
        },
        {
          title: '审核状态',
          minWidth: 120,
          key: 'dept_audit_status',
          render: (h, params) => {
            let date = '未知状态'
            let dept_audit_status = params.row.dept_audit_status
            let leader_audit_status = params.row.leader_audit_status
            if (dept_audit_status === 'draft') {
              date = '未提报'
            } else if (dept_audit_status === 'commit') {
              date = '部门已审核'
            } else if (dept_audit_status === 'audited' && leader_audit_status === 'unaudited') {
              date = '分项已审核'
            } else if (dept_audit_status === 'audited' && leader_audit_status === 'audited') {
              date = '区已审核'
            }
            return h('div', date)
          }
        },
        {
          title: '操作',
          slot: 'action',
          fixed: 'right',
          minWidth: 180,
          align: 'center'
        }
      ],
      dataList: [],
      pageInfo: {
        flag: 1,
        pageNo: 1,
        pageSize: 10,
        total: 0
      }
    }
  },
  methods: {
    toDetail (imp_date) {
      this.$router.push({ name: 'public-place-add', query: { imp_date: this.$common.moment(imp_date).format('YYYY-MM-DD'), showDetail: true } })
    },
    toEdit (imp_date) {
      this.$router.push({ name: 'public-place-add', query: { imp_date: this.$common.moment(imp_date).format('YYYY-MM-DD') } })
    },
    deleteData () {
      deletes({ id: this.currentDelId }).then(({ data }) => {
        let { errcode } = data
        if (errcode === 0) {
          this.$Message.success('删除成功!')
          this.currentDelId = ''
          this.getTableData()
        } else {
          this.$Message.warning('删除失败!')
        }
      })
    },
    deleteDataModal (id) {
      this.currentDelId = id
      this.modal = true
    },
    changePage (index) {
      this.pageInfo.pageNo = index
      this.getTableData()
    },
    getTableData () {
      findPageList(this.pageInfo).then(({ data }) => {
        let { data: res } = data
        this.dataList = res.results
        this.pageInfo.total = res.totalRecord
      })
    }
  },
  created () {
    this.getTableData()
  }
}
</script>
<style scoped lang="less" >
</style>
